<?php
//Nguyen Van Binh
//suongmumc@gmail.com

defined( '_VALID_NVB' ) or die( 'Direct Access to this location is not allowed.' );
$idc=intval($_GET['idc']);
$id=intval($_GET['id']);
$idmenu=intval($_GET['idmenu']);
if(!$id){
	$tpl = new TemplatePower("template/news.htm");
	$tpl->prepare();
		
	$tpl->assignGlobal("site_address",$site_address);
	$tpl->assign("cat_name",Get_Cat_Name('cat','id_cat',$idc));
	$tpl->assign("pathpage1",Get_Main_Cat_Name_path($idc));
	$sql="SELECT * FROM news WHERE active=1 AND id_cat IN(".Get_Id_Cat($idc).") ORDER BY thu_tu DESC, id_news DESC";
	$db=$DB->query($sql);
	$db=phan_trang_rewrite($_GET['p'],$site_address.get_url_news($idc),$sql,8,8);
	$i=0;
	while($rs=mysql_fetch_array($db['db'])){
		$tpl->newBlock("new_list");
		$i++;
		$tpl->assign("name",$rs['name']);	
		if($rs['ngay_dang']>0)
		$tpl->assign("createdate"," (".date('d/m/Y | H:i',$rs['ngay_dang']).")");
		$tpl->assign("intro",$rs['intro']);	
		if ($rs['small_image']){
			$tpl->assign("image","<img alt='".clean_url($rs['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs['small_image']."' align='left' border='0'  class='imagenews'  >");
		}	
		
		$tpl->assign("link_detail",$site_address.get_url_news($rs['id_cat']).clean_url($rs['name'])."_".$rs['id_news'].'.html');
		if($i%2==0) $tpl->assign("breakrow","</tr><tr>");
	}
	if($db['cac_trang']){
		$tpl->newBlock("showpage");
		$tpl->assignGlobal("pages",$db['cac_trang']);	
	}
	
	$tpl->printToScreen();
}else{
	$tpl = new TemplatePower("template/newsdetail.htm");
	$tpl->prepare();
	$tpl->assignGlobal("site_address",$site_address);
	$tpl->assign("cat_name",Get_Cat_Name('cat','id_cat',$idc));
	$tpl->assign("pathpage1",Get_Main_Cat_Name_path($idc));
	$sql="SELECT * FROM news WHERE active=1 AND id_news=$id";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$tpl->assign("name",$rs['name']);
		$tpl->assign("intro",$rs['intro']);
		if($rs['ngay_dang']>0)
			$tpl->assign("createdate"," (".date('d/m/Y | H:i',$rs['ngay_dang']).")");
		$tpl->assign("content",$rs['content']);
		if($rs['imgshowdetail']==1){
			if ($rs['normal_image']){
				$tpl->assign("image","<img width='180'  alt='".clean_url($rs['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs['normal_image']."' align='left' border='0' style='margin-right:5px;'>");
			}	
			elseif ($rs['small_image']){
				$tpl->assign("image","<img alt='".clean_url($rs['name'])."' src='".$site_address.$CONFIG['upload_image_path'].$rs['small_image']."' align='left' border='0' style='margin-right:5px;' >");
			}	
		}
		$tpl->assign("link_detail",$site_address.get_url_news($rs['id_cat']).clean_url($rs['name'])."_".$rs['id_news'].'.html');
		$DB->query("UPDATE news SET hit=hit+1 WHERE id_news=$id");
	}
	
	//tin khac	
	$sql="SELECT COUNT(id_news) as dem FROM news WHERE id_news>$id AND id_cat IN(".Get_Id_Cat($idc).") ORDER BY id_news DESC";
	$db=$DB->query($sql);
	$rs=mysql_fetch_array($db);
	$dem=intval($dem);
	if($dem<=5){
		$dem=$dem;	
	}else{
		$dem=$dem-5;	
	}
	
	$sql="SELECT * FROM news WHERE active=1 AND id_news>$id AND id_cat IN(".Get_Id_Cat($idc).") ORDER BY id_news DESC LIMIT $dem,5";
	$db=$DB->query($sql);
	if(mysql_num_rows($db)>0){
		$tpl->newBlock("neweat");
		while($rs=mysql_fetch_array($db)){
			$tpl->newBlock("list_news_other_new");
			$tpl->assign("name",$rs['name']);	
			if($rs['ngay_dang']>0)
			$tpl->assign("createdate"," (".date('d/m/Y | H:i',$rs['ngay_dang']).")");
			$tpl->assign("link_detail",$site_address.get_url_news($rs['id_cat']).clean_url($rs['name'])."_".$rs['id_news'].'.html');
			
		}
	}
	$sql="SELECT * FROM news WHERE active=1 AND id_news<$id AND id_cat IN(".Get_Id_Cat($idc).") ORDER BY id_news DESC LIMIT 0,10";
	$db=$DB->query($sql);
	while($rs=mysql_fetch_array($db)){
		$tpl->newBlock("list_news_other");
		$tpl->assign("name",$rs['name']);	
		if($rs['ngay_dang']>0)
			$tpl->assign("createdate"," (".date('d/m/Y | H:i',$rs['ngay_dang']).")");
			$tpl->assign("link_detail",$site_address.get_url_news($rs['id_cat']).clean_url($rs['name'])."_".$rs['id_news'].'.html');
	}
	$tpl->printToScreen();
}


?>